home *** CD-ROM | disk | FTP | other *** search
/ SGI Desktop Special Edition 1.1 / SGI Desktop Special Edition 1.1.iso / dist / SoftWindows2.idb / usr / lib / SoftWindows2 / bin / scripts / updisk.pl.z / updisk.pl
Encoding:
Perl Script  |  1995-11-13  |  3.0 KB  |  115 lines

  1. #!/usr/sbin/perl
  2.  
  3. $K=1024;        #1-K
  4. $Meg=$K*$K;        #1-Meg
  5. $XCONFIRM='/usr/bin/X11/xconfirm';
  6.  
  7. $NEW_DISK_SPACE_REQUIRED=90*$K;        #size in Kilobytes needed
  8.  
  9. #return codes
  10. $CREATE_NEW_HD=0;                # 0 - ok create new hard disk
  11. $UPGRADE_FAILED=1;                # 1 - mv or cp of old HD failed - reason unknown
  12. $BOOT_OFF_NEW=2;                # 2 - the new is ready to be booted off of
  13. $CONTINUE=3;                    # 3 - Continue back in SWIN
  14. $E_NOSPACE=4;                    # 4 - we are exiting for not enough space -
  15.                                 #      SWIN will give user a 2nd chance here
  16.  
  17. #$name=getpwuid($<);
  18. #$home=(getpwuid($<))[7];
  19. $name=$ENV{"USER"};
  20. $home=$ENV{"HOME"};
  21.  
  22. $OLD_DISK="$home/WIN31-$name.hdf";
  23. $NEW_DISK="$home/WIN311-$name.hdf";
  24.  
  25. Retry:
  26.  
  27. #sanity check
  28. if (-e $NEW_DISK) { exit $BOOT_OFF_NEW; }
  29.  
  30.  
  31. #get free disk space on home device
  32. $_=`/usr/sbin/df -k $home|/bin/tail -1`;
  33. ($free_space)=/.{27}\s*\S+\s+\d+\s+\d+\s+(\d+).*/;
  34.  
  35.  
  36. #find size of old hard disk in K
  37.  
  38. $old_size=((($old_exists=-R $OLD_DISK)?-s $OLD_DISK:0)+$K-1)/$K;
  39.  
  40. if (!$old_exists) {
  41.     #nothing to copy -- do we have enough space to create a new HD?
  42.     if ($NEW_DISK_SPACE_REQUIRED < $free_space) { exit $CREATE_NEW_HD;}
  43.     else {
  44.         exit $E_NOSPACE;
  45.     }
  46. }
  47.  
  48. #old exists, enough space to copy the old?
  49.  
  50. if ($old_size<$free_space) {
  51.     if (system("cp -p $OLD_DISK $NEW_DISK")) {
  52.         system("rm $NEW_DISK");        #remove any turds
  53.         if ($NEW_DISK_SPACE_REQUIRED < $free_space) { exit $CREATE_NEW_HD; }
  54.         else {
  55.             exit $E_NOSPACE;
  56.         }
  57.     }
  58.     #getting here means cp succeeded...
  59.     exit $BOOT_OFF_NEW;
  60. }
  61.  
  62. #Ok, we got here...what to do.
  63. #first -- we *could* rename the old
  64. #second, we *might* be able to create a new HD
  65. #third, we offer to exit for them!
  66. if ($NEW_DISK_SPACE_REQUIRED < $free_space) {
  67.     #3 choice popup!
  68.     $prog="$XCONFIRM".' -c -b "Continue" -b "Create" -B "Upgrade" -b "Retry" '.
  69.         '-header "Insufficient Space" '.
  70.         '-t "There is not enough space to make" '.
  71.         '-t "a backup of your current hard disk." '.
  72.         '-t "You can IRREVERSIBLY <Upgrade> your" '.
  73.         '-t "current hard disk, <Create> a new hard" '.
  74.         '-t "disk, or <Continue>." '.
  75.         '-icon question -geometry "360x190"';
  76. } else {
  77.     #2 choice popup
  78.     $prog="$XCONFIRM".' -c -b "Continue" -B " Upgrade" -b "Retry" '.
  79.         '-header "Insufficient Space" '.
  80.         '-t "There is not enough space to make" '.
  81.         '-t "a backup of your current hard disk" '.
  82.         '-t "or to create a new hard disk." '.
  83.         '-t "You can IRREVERSIBLY <Upgrade> your" '.
  84.         '-t "current hard disk, or <Continue> with" '.
  85.         '-t "more options." '.
  86.         '-icon question -geometry "360x190"';
  87. }
  88.  
  89. $_=`$prog`;
  90.  
  91. if (/Upgrade/) {
  92.     if (system("mv $OLD_DISK $NEW_DISK")) {
  93.         # yuck this failed.  Not much to do
  94.         $prog="$XCONFIRM".' -c -B "Continue" -b "Retry" '.
  95.             '-header "Cannot Rename"" '.
  96.             '-t "Your old hard disk could not be " '.
  97.             '-t "renamed.  This might be a permission" '.
  98.             '-t "problem.  " '.
  99.             '-icon question -geometry "360x190"';
  100.         $_=`$prog`;
  101.  
  102.         if (/Retry/) {
  103.             goto Retry;
  104.         }
  105.         exit $CONTINUE;
  106.     }
  107.     exit $BOOT_OFF_NEW;
  108. } elsif (/Continue/) {
  109.     exit $CONTINUE;
  110. } elsif (/Retry/) {
  111.     goto Retry;
  112. } else {
  113.     exit $CREATE_NEW_HD;
  114. }
  115.